<!DOCTYPE html>

<html>
<head>
  <title>parser.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="../../../docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>parser.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <p>Sets up the parser generated by canopy to use the
<a href="./javascript/node.html">Node</a> subclasses in the generated tree. This is all
a bit of a hack that is dependent on how canopy creates nodes in its parse
tree.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> parser <span class="hljs-keyword">from</span> <span class="hljs-string">'./grammar.peg'</span>;

<span class="hljs-keyword">import</span> Node <span class="hljs-keyword">from</span> <span class="hljs-string">'./node.js'</span>;
<span class="hljs-keyword">import</span> Root <span class="hljs-keyword">from</span> <span class="hljs-string">'./root.js'</span>;
<span class="hljs-keyword">import</span> Regexp <span class="hljs-keyword">from</span> <span class="hljs-string">'./regexp.js'</span>;
<span class="hljs-keyword">import</span> Match <span class="hljs-keyword">from</span> <span class="hljs-string">'./match.js'</span>;
<span class="hljs-keyword">import</span> MatchFragment <span class="hljs-keyword">from</span> <span class="hljs-string">'./match_fragment.js'</span>;
<span class="hljs-keyword">import</span> Anchor <span class="hljs-keyword">from</span> <span class="hljs-string">'./anchor.js'</span>;
<span class="hljs-keyword">import</span> Subexp <span class="hljs-keyword">from</span> <span class="hljs-string">'./subexp.js'</span>;
<span class="hljs-keyword">import</span> Charset <span class="hljs-keyword">from</span> <span class="hljs-string">'./charset.js'</span>;
<span class="hljs-keyword">import</span> CharsetEscape <span class="hljs-keyword">from</span> <span class="hljs-string">'./charset_escape.js'</span>;
<span class="hljs-keyword">import</span> CharsetRange <span class="hljs-keyword">from</span> <span class="hljs-string">'./charset_range.js'</span>;
<span class="hljs-keyword">import</span> Literal <span class="hljs-keyword">from</span> <span class="hljs-string">'./literal.js'</span>;
<span class="hljs-keyword">import</span> Escape <span class="hljs-keyword">from</span> <span class="hljs-string">'./escape.js'</span>;
<span class="hljs-keyword">import</span> AnyCharacter <span class="hljs-keyword">from</span> <span class="hljs-string">'./any_character.js'</span>;
<span class="hljs-keyword">import</span> Repeat <span class="hljs-keyword">from</span> <span class="hljs-string">'./repeat.js'</span>;
<span class="hljs-keyword">import</span> RepeatAny <span class="hljs-keyword">from</span> <span class="hljs-string">'./repeat_any.js'</span>;
<span class="hljs-keyword">import</span> RepeatOptional <span class="hljs-keyword">from</span> <span class="hljs-string">'./repeat_optional.js'</span>;
<span class="hljs-keyword">import</span> RepeatRequired <span class="hljs-keyword">from</span> <span class="hljs-string">'./repeat_required.js'</span>;
<span class="hljs-keyword">import</span> RepeatSpec <span class="hljs-keyword">from</span> <span class="hljs-string">'./repeat_spec.js'</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Canopy creates an instance of SyntaxNode for each element in the tree, then
adds any necessary fields to that instance. In this case, we’re replacing
the default class with the Node class.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>parser.Parser.SyntaxNode      = Node;</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>Once the SyntaxNode instance is created, the specific node type object is
overlayed onto it. This causes the module attribute on the Node to be set,
which updates the Node instance into the more specific “subclass” that is
used for rendering.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>parser.Parser.Root            = { <span class="hljs-attr">module</span>: Root };
parser.Parser.Regexp          = { <span class="hljs-attr">module</span>: Regexp };
parser.Parser.Match           = { <span class="hljs-attr">module</span>: Match };
parser.Parser.MatchFragment   = { <span class="hljs-attr">module</span>: MatchFragment };
parser.Parser.Anchor          = { <span class="hljs-attr">module</span>: Anchor };
parser.Parser.Subexp          = { <span class="hljs-attr">module</span>: Subexp };
parser.Parser.Charset         = { <span class="hljs-attr">module</span>: Charset };
parser.Parser.CharsetEscape   = { <span class="hljs-attr">module</span>: CharsetEscape };
parser.Parser.CharsetRange    = { <span class="hljs-attr">module</span>: CharsetRange };
parser.Parser.Literal         = { <span class="hljs-attr">module</span>: Literal };
parser.Parser.Escape          = { <span class="hljs-attr">module</span>: Escape };
parser.Parser.AnyCharacter    = { <span class="hljs-attr">module</span>: AnyCharacter };
parser.Parser.Repeat          = { <span class="hljs-attr">module</span>: Repeat };
parser.Parser.RepeatAny       = { <span class="hljs-attr">module</span>: RepeatAny };
parser.Parser.RepeatOptional  = { <span class="hljs-attr">module</span>: RepeatOptional };
parser.Parser.RepeatRequired  = { <span class="hljs-attr">module</span>: RepeatRequired };
parser.Parser.RepeatSpec      = { <span class="hljs-attr">module</span>: RepeatSpec };

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> parser;</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
